<%@ page import="com.hc.commodity.dao.impl.DeptDaoImpl" %>
<%@ page import="com.hc.commodity.dao.DeptDao" %>
<%@ page import="com.hc.commodity.pojo.Dept" %>
<%@ page import="java.util.List" %>
<%@ page import="com.hc.commodity.dao.impl.EmpDaoImpl" %>
<%@ page import="com.hc.commodity.dao.EmpDao" %>
<%@ page import="com.hc.commodity.pojo.Emp" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/9
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>员工管理</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
</head>
<body>

<%
    //当前页和每页共展示多少条数
    int pageNo = 1;
    int pageSize = 10;
    //获取请求参数
    String begin = request.getParameter("pageno");
    if (begin != null){
        pageNo = Integer.parseInt(begin);
        if (pageNo == 0){
            pageNo = 1;
        }
    }
    //查询数据库
    EmpDao empDao = new EmpDaoImpl();
    List<Emp> empList = empDao.findByPage((pageNo - 1) * pageSize, pageSize);
    //总记录数
    int allNumber = empDao.findAllNumber();
    //总页数
    int totalPage = allNumber / pageSize;
    if (allNumber%pageSize != 0){
        totalPage++;
    }
    //将结果存入数据域中
    pageContext.setAttribute("empList",empList);
    pageContext.setAttribute("pageNo",pageNo);
    pageContext.setAttribute("totalPage",totalPage);
%>

<div class="container">
    <ul class="breadcrumb">
        <li><a href="#">员工管理系统</a></li>
        <li><a href="#">员工管理</a></li>
    </ul>
    <div>
        <a href="empInsert.jsp" class="btn btn-primary"> 新增 </a>
    </div>
    <table class="table table-striped table-hover table-bordered">
        <tr>
            <th>员工编号</th>
            <th>姓名</th>
            <th>职位</th>
            <th>上司</th>
            <th>入职日期</th>
            <th>工资</th>
            <th>奖金</th>
            <th>部门编号</th>
            <th>其他</th>
        </tr>
        <c:forEach items="${empList}" var="emp">
            <tr>
                <td>${emp.empno}</td>
                <td>${emp.ename}</td>
                <td>${emp.job}</td>
                <td>${emp.mgr}</td>
                <td>${emp.hiredate}</td>
                <td>${emp.sal}</td>
                <td>${emp.comm}</td>
                <td>${emp.deptno}</td>
                <td>
                    <a href="empUpdata.jsp?id=${emp.empno}">修改</a>
                    <a href="empDelete.jsp?id=${emp.empno}">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <div style="float: right">
        <span>当前第：${pageNo}页，共${totalPage}页</span>
        <a href="empManage.jsp?pageno=1">首页</a>
        <a href="empManage.jsp?pageno=${pageNo-1}">上页</a>
        <a href="empManage.jsp?pageno=${pageNo+1}">下页</a>
        <a href="empManage.jsp?pageno=${totalPage}">尾页</a>
    </div>
</div>
</body>
</html>
